const fs = require('fs')

const jwt = require('jsonwebtoken')
class AuthController {
  async login(ctx, next) {
    const {user_id,username} = ctx.user
    const privateKey = fs.readFileSync('src/app/keys/private.key')
    const token = jwt.sign({
      user_id,
      username
    }, privateKey, {
      expiresIn: 60 * 60 * 24,
      algorithm:'RS256'
    })
    ctx.body = {
      data: {
        token,
        userId: user_id,
        username
      },
      meta: {
        msg: '登录成功',
        status:200
      }
    }
  }
}
module.exports = new AuthController()